package com.zone.api.di

import com.zone.api.constant.IS_DEMO
import com.zone.api.database.AppConfig
import com.zone.api.database.ObjectBox
import com.zone.api.http.InterceptorKey
import com.zone.api.service.ApiService
import dagger.Module
import dagger.Provides
import dagger.multibindings.IntoMap
import okhttp3.Interceptor
import retrofit2.Retrofit
import javax.inject.Named
import javax.inject.Singleton

@Module(includes = [RetrofitModule::class])
class ApiModule {

    @Singleton
    @Named(RetrofitModule.NAME_DEBUG)
    @Provides
    fun isDebug() = IS_DEMO

    @Singleton
    @Provides
    fun getAppConfig()  = AppConfig()

    @Singleton
    @Provides
    fun getApiService(retrofit: Retrofit): ApiService =
        retrofit.create(ApiService::class.java)

    @Singleton
    @Provides
    fun getObjectBox(): ObjectBox = ObjectBox()

    @Provides
    @IntoMap
    @InterceptorKey(1)
    fun getSignInterceptor(): Interceptor {
        return SignInterceptor()
    }
    @Provides
    @IntoMap
    @InterceptorKey(2)
    fun getApiInterceptor(): Interceptor {
        return ApiInterceptor()
    }

}